package zhihui.mobile.ui.utils;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.zgm.utils.*;

import zhihui.mobile.R;
import zhihui.mobile.app.MyApplication;
import zhihui.mobile.ui.IView;
import zhihui.mobile.ui.main.MainActivity;
import zhihui.mobile.ui.myself.MySelfMainActivity;
import zhihui.mobile.ui.shop.ShopMainActivity;

/**
 * Created by 张公铭 on 2017/7/13 0013.
 */

public class UiFooterLayout extends LinearLayout
{
    private Context mContext;

    private RelativeLayout rl_main;
    private RelativeLayout rl_shop;
    private RelativeLayout rl_service;
    private RelativeLayout rl_myself;

    private ImageView iv_main;
    private ImageView iv_shop;
    private ImageView iv_service;
    private ImageView iv_myself;

    private TextView tv_main;
    private TextView tv_shop;
    private TextView tv_service;
    private TextView tv_myself;

    private IView view;

    public enum Meun
    {
        Main, Service, Shop, Myself;
    }

    public UiFooterLayout(Context context)
    {
        this(context, null);
    }

    public UiFooterLayout(Context context, @Nullable AttributeSet attrs)
    {
        this(context, attrs, 0);
    }

    public UiFooterLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr)
    {
        super(context, attrs, defStyleAttr);
        mContext = context;
        init();
    }

    public void setIView(IView iView)
    {
        view = iView;
    }

    private void init()
    {
        LayoutInflater.from(mContext).inflate(R.layout.ui_footer, this);
        rl_main = (RelativeLayout) findViewById(R.id.rl_footer_main);
        rl_main.setOnClickListener(new OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                Intent intent = new Intent(mContext, MainActivity.class);
                mContext.startActivity(intent);
            }
        });

        rl_shop = (RelativeLayout) findViewById(R.id.rl_footer_shop);
        rl_shop.setOnClickListener(new OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                Intent intent = new Intent(mContext, ShopMainActivity.class);
                mContext.startActivity(intent);
            }
        });

        rl_service = (RelativeLayout) findViewById(R.id.rl_footer_service);
        rl_service.setOnClickListener(new OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                com.zgm.utils.UiUtils.ToastInCenter(mContext, "敬请期待！", Toast.LENGTH_SHORT);
            }
        });
        rl_service.setVisibility(GONE);

        rl_myself = (RelativeLayout) findViewById(R.id.rl_footer_myself);
        rl_myself.setOnClickListener(new OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                Intent intent = new Intent(mContext, MySelfMainActivity.class);
                mContext.startActivity(intent);
            }
        });


        iv_main = (ImageView) findViewById(R.id.iv_footer_main);
        iv_main.setImageResource(R.drawable.footer_main_selected);

        iv_shop = (ImageView) findViewById(R.id.iv_footer_shop);
        iv_service = (ImageView) findViewById(R.id.iv_footer_service);
        iv_myself = (ImageView) findViewById(R.id.iv_footer_myself);

        tv_main = (TextView) findViewById(R.id.tv_footer_main);
        tv_main.setTextColor(Color.parseColor("#4b85e4"));

        tv_service = (TextView) findViewById(R.id.tv_footer_service);
        tv_shop = (TextView) findViewById(R.id.tv_footer_shop);
        tv_myself = (TextView) findViewById(R.id.tv_footer_myself);
    }

    public void change(Meun type)
    {
        iv_main.setImageResource(R.drawable.footer_main_normal);
        tv_main.setTextColor(Color.parseColor("#999999"));

        iv_shop.setImageResource(R.drawable.footer_shop_noraml);
        tv_shop.setTextColor(Color.parseColor("#999999"));

        iv_service.setImageResource(R.drawable.footer_service_normal);
        tv_service.setTextColor(Color.parseColor("#999999"));

        iv_myself.setImageResource(R.drawable.footer_myself_normal);
        tv_myself.setTextColor(Color.parseColor("#999999"));

        if (type == Meun.Main)
        {
            iv_main.setImageResource(R.drawable.footer_main_selected);
            tv_main.setTextColor(Color.parseColor("#4b85e4"));
        } else if (type == Meun.Service)
        {
            iv_service.setImageResource(R.drawable.footer_service_selected);
            tv_service.setTextColor(Color.parseColor("#4b85e4"));
        } else if (type == Meun.Shop)
        {
            iv_shop.setImageResource(R.drawable.footer_shop_selected);
            tv_shop.setTextColor(Color.parseColor("#4b85e4"));
        } else if (type == Meun.Myself)
        {
            iv_myself.setImageResource(R.drawable.footer_myself_selected);
            tv_myself.setTextColor(Color.parseColor("#4b85e4"));
        }
    }
}
